package CollegeInformation;

import javax.swing.*;
import java.awt.event.*;

public class addDialog extends JDialog {
    private JPanel contentPane;
    private JButton buttonOK;
    private JButton buttonCancel;
    private JTextField textField1;
    private JTextField textField2;
    private JTextField textField3;
    private JTextField textField4;
    private JTextField textField5;
    private JTextField textField6;
public addDialog(){};
    public addDialog(String id) {
        setContentPane(contentPane);
        setModal(true);

        buttonOK.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                String name = textField1.getText();
                String sex = textField2.getText();
                String  age= textField3.getText();
                String department = textField4.getText();
                String major = textField5.getText();
                String title = textField6.getText();
                Service2.addFunc1(id,name,sex,Integer.parseInt(age),department,major,title);
                dispose();
            }
        });
        buttonCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        });

        // 单击十字时调用 onCancel()
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                onCancel();
            }
        });

        // 遇到 ESCAPE 时调用 onCancel()
        contentPane.registerKeyboardAction(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    }

    private void onCancel() {
        // 必要时在此处添加您的代码
        dispose();
    }

    public static void main(String[] args) {
        addDialog dialog = new addDialog();
        dialog.pack();
        dialog.setVisible(true);
        System.exit(0);
    }


}
